package com.jwds.digital.bios.business.api.controller.basic;

import cn.hutool.core.lang.tree.Tree;
import com.jwds.digital.bios.business.core.infrastructure.dto.basic.BasicDictReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.basic.BasicOperateLogReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.belt.BasicPowerTypeReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.entity.basic.BasicDict;
import com.jwds.digital.bios.business.core.infrastructure.vo.basic.BasicDictRespVO;
import com.jwds.digital.bios.business.service.service.basic.IBasicDictService;
import com.jwds.tdc.framework.application.lib.BaseResponse;
import com.jwds.tdc.framework.application.lib.page.PageRequest;
import com.jwds.tdc.framework.application.lib.page.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Description BasicDictController
 * @Author xiao  xun
 * @Date 2024-12-07
 */
@Slf4j
@Api(tags = "字典信息")
@RestController
@RequestMapping("/basic/dict")
public class BasicDictController {
    @Resource
    private IBasicDictService service;
    @PostMapping("/pagelist")
    @ApiOperation(value = "分页查询")
    public BaseResponse<PageResponse<BasicDictRespVO>> page(@Valid @RequestBody PageRequest<BasicDictReqDTO> pageRequest) {
        PageResponse<BasicDictRespVO> respVoPage = service.page(pageRequest);
        return BaseResponse.success(respVoPage);
    }
    @PostMapping("/tree")
    @ApiOperation(value = "树形查询")
    public BaseResponse<List<Tree<String>>> getDictTree() {
         List<Tree<String>> tree = service.getTree();
        return BaseResponse.success(tree);
    }

    @PostMapping("/")
    @ApiOperation(value = "新增")
    public BaseResponse<?> add(@Validated @RequestBody BasicDictReqDTO reqDto) {
        service.add(reqDto);
        return BaseResponse.success();
    }

    @PutMapping("/")
    @ApiOperation(value = "更新对象")
    public BaseResponse<?> update(@Validated @RequestBody BasicDictReqDTO reqDto) {
        service.update(reqDto);
        return BaseResponse.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除对象")
    public BaseResponse<?> delete(@PathVariable("id") Long id) {
        service.delete(id);
        return BaseResponse.success();
    }


}
